﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using _4mvcBlog.Core;
using System.Web.Mvc;

namespace _4mvcBlog.Controllers
{
    public class FilesController : BlogBaseController
    {
        [AntiOutSiteLink(FileType.Image)]
        public ActionResult Image(string file)
        {
            //string file = id;
            string contentType;
            int index = file.LastIndexOf(".") + 1;
            string extension = file.Substring(index).ToUpperInvariant();

            // Fix for IE not handling jpg image types
            if (string.Compare(extension, "JPG") == 0)
                contentType = "image/jpeg";
            else
                contentType = "image/" + extension;
            return File(Server.MapPath("~/app_data/files/" + file), contentType);
        }

        [AntiOutSiteLink(FileType.File)]
        public ActionResult File(string id)
        {
            return Content("File From 4mvc");
        }
    }
}
